<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl"
                 class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="item.id===0?'mui-control-item mui-active':'mui-control-item'" href="#"
                       v-for="(item,index) in imgListBar" :key="index" @click.prevent="getimgList(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <ul class="imgList">
            <li v-for="item in imgList" :key="item.id">
                <router-link :to="'/home/imageInfor/'+item.id">
                    <img v-lazy="item.img_url">
                </router-link>
                <div class="infor">
                    <p class="infor-title">{{item.title}}</p>
                    <p class="infor-introduce">{{item.zhaiyao}}</p>
                </div>
            </li>
        </ul>
    </div>
</template>

<script>
    import mui from '../../lib/mui/dist/js/mui.min.js'

    export default {
        data: function () {
            return {
                imgListBar: [],
                imgList: [],
            }
        },
        created() {
            this.getimgListBar();
            this.getimgList(0);
        },
        mounted() {
            mui('.mui-slider-indicator').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods: {
            getimgListBar() {
                this.$http.get('http://www.liulongbin.top:3005/api/getimgcategory').then(data => {
                    this.imgListBar = data.body.message;
                    this.imgListBar.unshift({title: '全部', id: 0});
                })
            },
            getimgList(id) {
                this.$http.get('http://www.liulongbin.top:3005/api/getimages/' + id).then(data => {
                    this.imgList = data.body.message;
                })
            },
        }
    }
</script>

<style lang="less" scoped>
    * {
        touch-action: pan-y;
    }

    .imgList {
        list-style: none;
        margin: 0;
        padding: 10px;

        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }

        li {
            text-align: center;
            margin-bottom: 10px;
            box-shadow: 0 0 6px #999;
            position: relative;

            img {
                width: 100%;
                height: 100%;
                vertical-align: middle;
            }
        }
    }

    .infor {
        position: absolute;
        bottom: 0;
        left: 0;
        background-color: rgba(51, 51, 51, 0.3);
        max-height: 80px;

        .infor-title {
            color: #e17055;
            font-size: 14px;
            margin-bottom: 0;
            font-weight: bold;
            text-align: left;
        }

        .infor-introduce {
            color: white;
            font-size: 10px;
            margin-bottom: 0;
            text-align: left;
        }
    }
</style>
